
#include "stm32f1xx.h"
#include <rtthread.h>
#include <rtdevice.h>
#include "drv_gpio.h"
#include "drv_spi.h"
#include "spi_flash_sfud.h"
#include "dfs_fs.h"
#include "spi_msd.h"
#include "easyblink.h"
#include "beep.h"

#define SPI2_BUS_DEV        "spi2"

#define SPI_DEV_SPI20       "spi20"
#define MTD_DEV_W25Q64      "W25Q64"

#define SPI_DEV_SPI21       "spi21"
#define MTD_DEV_SD          "SD"


static int rt_spi_flash_msd_mount(void)
{
    rt_hw_spi_device_attach(SPI2_BUS_DEV, SPI_DEV_SPI20, GPIOB, GPIO_PIN_12);
    if (RT_NULL != rt_sfud_flash_probe(MTD_DEV_W25Q64, SPI_DEV_SPI20))
    {
        if (dfs_mount(MTD_DEV_W25Q64, "/", "elm", 0, 0) == 0)
        {
            rt_kprintf("spi flash mount to / !\n");
        }
        else
        {
            rt_kprintf("spi flash mount to / failed!\n");
        }
    }

    rt_hw_spi_device_attach(SPI2_BUS_DEV, SPI_DEV_SPI21, GPIOD, GPIO_PIN_2);
    if (RT_EOK == msd_init(MTD_DEV_SD, SPI_DEV_SPI21))
    {
        if (dfs_mount(MTD_DEV_SD, "/sd", "elm", 0, 0) == 0)
        {
            rt_kprintf("spi sd mount to /sd !\n");
        }
        else
        {
            rt_kprintf("spi sd mount to /sd failed!\n");
        }
    }
    
    return RT_EOK;
}
INIT_ENV_EXPORT(rt_spi_flash_msd_mount);


int rt_hw_led_init(void)
{
    easyblink_init_led(GET_PIN(E, 5), PIN_LOW);

    return 0;
}
INIT_APP_EXPORT(rt_hw_led_init);

int rt_hw_beep_init(void)
{
    beep_init(GET_PIN(B, 8), PIN_LOW);

    return 0;
}
INIT_APP_EXPORT(rt_hw_beep_init);





